import axios from "axios";
import config from "@/util/config.js"
//创建一个axios的对象
const bomAPI = {
    mdBaseUrl: config.mdUrl+"/md",
    mdProMat: "/bom",
    timeout: 5000,
    getOrderBom(param, callback) {
        axios.get(this.mdBaseUrl + this.mdProMat + "/query/" + param.orderId).then((res) => {
            callback(res.data);
        })
    },
    //添加bom组成
    addOrderBom(param, orderId, callback) {
        axios.request({
            url: this.mdBaseUrl + this.mdProMat + "/add/" + orderId,
            method: "post",
            data: JSON.stringify(param),
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            }
        }).then((res) => {
            callback(res.data)
        })
    },
    //删除bom信息
    deleteBom(param, callback) {
        axios.request(
            {
                url: this.mdBaseUrl + this.mdProMat + "/delete",
                method: "delete",
                data: JSON.stringify(param),
                headers: {
                    "Content-Type": "application/json;charset=UTF-8"
                }
            }
        ).then((res) => {
                callback(res.data)
            }
        )
    },

    //修改BOM信息
    updateBom(param,productId, callback) {
        axios.request({
            url: this.mdBaseUrl + this.mdProMat + "/update/"+productId,
            method: "put",
            data: param,
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            }
        }).then((res) => {
            callback(res.data)
        })
    },
}
export default bomAPI;